export default{
	getToday(){
		let date=new Date;
		let res={};
		res.year=date.getFullYear();
		res.month=date.getMonth()+1;
		res.date=date.getDate();
		console.log(`${res.year.toString()}-${res.month.toString()}-${res.date.toString()}`)
		return `${res.year.toString()}-${res.month.toString()}-${res.date.toString()}`
	},
	handleDatas(date){
		let info=date.split("-")
		console.log(info)
		const yearData=getApp().globalData.listData.filter(i=>{return i.year===info[0]})
		const monthData=yearData.filter(i=>i.month===info[1])
		const dayData=monthData.filter(i=>i.date===date)
	    const ydata=this.fliterData(yearData)
		const mdata=this.fliterData(monthData)
		const dData=this.fliterData(dayData)
		const ydataOut=this.handleData(ydata.out,true)
		const ydataIn=this.handleData(ydata.in,false)
		const mdataOut=this.handleData(mdata.out,true)
		const mdataIn=this.handleData(mdata.in,false)
		const dDataOut=this.handleData(dData.out,true)
		const dDataIn=this.handleData(dData.in,false)
		let result={dDataOut,dDataIn,mdataOut,mdataIn,ydataOut,ydataIn}
		console.log(result)
		return result
	},
	fliterData(data){
		let res={out:[],in:[]}
		data.forEach((i)=>{
			if(i.out){
				res.out.push(i)
			}else{
				res.in.push(i)
			}
		})
		return res
	},
	handleData(data,status){
		let valueOut={
			"food":0,
			"clothes":0,
			"traffic":0,
			"study":0,
			"play":0,
			"qita":0
		}
		let valueIn={
			"jianzhi":0,
			"shenghuofei":0,
			"touzi":0,
			"tuikuan":0,
			"hongbao":0,
			"jiangjin":0
		}
		let tips={
					"food":"餐饮",
					"clothes":"服饰",
					"traffic":"交通",
					"qita":"其他",
					"play":"娱乐",
					"study":"学习",
					"jianzhi":"兼职",
					"shenghuofei":"生活费",
					"touzi":"投资",
					"tuikuan":"退款",
					"hongbao":"红包",
					"jiangjin":"奖金",
				}
		let res=[]
		if(status){
			data.forEach(i=>{
				valueOut[i.type]++;
			})
			for(let x in valueOut){
				res.push({value:valueOut[x],text:tips[x]})
			}
		}else{
			data.forEach(i=>{
				valueIn[i.type]++;
			})
			
			for(let x in valueIn){
				res.push({value:valueIn[x],text:tips[x]})
			}
		}
		return res;
	},
	sum(data){
		const date=new Date
		const year=date.getFullYear()
		const month=date.getMonth()+1
		console.log(year)
		console.log(month)
		console.log(data)
		const arr=data.filter(i=>{
			console.log(i.year)
			console.log(i.month)
			return i.year===year.toString()&&i.month===month.toString()
			})
		console.log(arr)
		let inSum=0,outSum=0;
		arr.forEach(i=>{
			if(i.out){
				outSum+=parseFloat(i.cost)
			}else{
				inSum+=parseFloat(i.cost)
			}
		})
		let sum=inSum-outSum
		return {sum,outSum,inSum}
	}
}